﻿<%@ Page Title="" Language="C#" MasterPageFile="Site.Master" AutoEventWireup="true" CodeBehind="Browse.aspx.cs" Inherits="WebControlsTest.RRBrowse" %>

<asp:Content ID="browseHead" ContentPlaceHolderID="pageHead" runat="server">
</asp:Content>

<asp:Content ID="browseContent" ContentPlaceHolderID="pageContent" runat="server">
	<br />
<%-- TODO: add js to dynamically expand fileExplorer to window size --%>
<%-- TODO: add header button bar above GridView including js to allow dynamic column width and sorting-by-column --%>
	<table class="browseFileExplorer unselectableText" cellpadding="0" cellspacing="0">
		<tbody>
			<!-- table of user action buttons and search bar -->
			<!-- Each row is a single cell containing a sub table. This allows independent column layout for each row. -->
			<tr>
				<td>
				<table class="browseActionTable" cellpadding="0">
				<tbody>
					<!-- row of dir actions -->
					<tr>
						<td>
						<table class="browseDirActionTable" cellpadding="2">
						<tbody>
						<tr>
							<!-- Dir Write -->
							<td>
								<asp:Button ID="uploadButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Upload" OnClick="uploadButtonClicked" />
							</td>
							<td>
								<asp:Button ID="newFolderButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="New Folder" OnClick="newFolderButtonClicked" />
							</td>
							<!-- Dir Admin -->
							<td>
								<asp:Button ID="dirPermButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Request Folder Permissions" OnClick="dirPermButtonClicked" />
							</td>
						</tr>
						</tbody>
						</table>
						</td>
					</tr>
					<!-- row of file actions -->
					<tr>
						<td>
						<table class="browseFileActionTable" cellpadding="2">
						<tbody>
						<tr>
							<!-- File Read -->
							<td>
								<asp:Button ID="downloadButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Download" OnClick="downloadButtonClicked" />
							</td>
							<%--td>		TODO
								<asp:Button ID="copyToButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Copy To" OnClick="copyToButtonClicked" />
							</td--%>
							<!-- File Write -->
							<%--td>		TODO
								<asp:Button ID="renameButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Rename" OnClick="renameButtonClicked" />
							</td--%>
							<!-- File Admin -->
							<td>
								<asp:Button ID="deleteButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Delete" OnClick="deleteButtonClicked" />
							</td>
							<%---td>		TODO
								<asp:Button ID="moveToButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Move To" OnClick="moveToButtonClicked" />
							</td--%>
							<td>
								<asp:Button ID="filePermButton" runat="server" CssClass="browseDownloadButton" Enabled="false" Text="Request File Permissions" OnClick="filePermButtonClicked" />
							</td>
						</tr>
						</tbody>
						</table>
						</td>
					</tr>
					<!-- Search Bar -->
					<!-- TODO: functionality not yet designed and/or implemented -->
					<%--tr>
						<td>
						<table class="browseFileActionTable" cellpadding="2">
						<tbody>
						<tr>
							<td>
								<asp:TextBox ID="searchText" MaxLength="32" runat="server"></asp:TextBox>
								<asp:Button ID="searchButton" runat="server" CssClass="masterLoginButton" Text="Search" 
								OnClick="searchButtonClicked" ValidationGroup="searchValidation"/>
								<asp:RequiredFieldValidator runat="server" ControlToValidate="searchText" ValidationGroup="searchValidation"
								ErrorMessage="<span style='color:#FF0000'>*</span>">
								</asp:RequiredFieldValidator>
								<asp:RegularExpressionValidator runat="server" ControlToValidate="searchText" ValidationGroup="searchValidation"
								ErrorMessage="<span style='color:#FF0000'> Please use at least 3 letters</span>"
								ValidationExpression="^[a-zA-Z ]{3,32}$">
								</asp:RegularExpressionValidator>
							</td>
						</tr>
						</tbody>
						</table>
						</td>
					</tr--%>
				</tbody>
				</table>
				</td>
			</tr>
			<!-- tree and grid views -->
			<tr>
				<td>
				<table class="browseExplorerTable" cellpadding="2">
				<tbody>
				<tr>
					<td>
						<div class="browseTreeDiv"> <!-- must put in div to get scroll bars instead of expanding to content -->
						<asp:TreeView ID="fileBrowserTree" runat="server" PopulateNodesFromClient="true" EnableClientScript="true" ShowLines="true"
							OnTreeNodePopulate="populateTreeNode" OnSelectedNodeChanged="treeNodeSelected" OnTreeNodeExpanded="treeNodeExpanded">
							<NodeStyle ForeColor="#000000" />
							<SelectedNodeStyle BackColor="#4848FF" ForeColor="HighlightText" BorderColor="#888888" BorderStyle="Dotted" BorderWidth="1" />
							<HoverNodeStyle BackColor="#EEEEEE" ForeColor="#111111" />
							<Nodes>
							</Nodes>
						</asp:TreeView>
						</div>
					</td>
					<td>
						<div class="browseGridDiv"> <!-- must put in div to get scroll bars instead of expanding to content -->
						<asp:GridView ID="fileBrowserGrid" runat="server" GridLines="None" AutoGenerateColumns="false" ShowHeaderWhenEmpty="true" AllowSorting="true"
							OnRowDataBound="gridRowDataBound" OnSelectedIndexChanged="gridRowSelected">
							<EmptyDataTemplate>
								<div class="browsePermCol"></div>
								<div class="browseNameCol"></div>
								<div class="browseModifiedCol"></div>
								<div class="browseCreatedCol"></div>
							</EmptyDataTemplate>
							<RowStyle CssClass="browseGridRow" />
							<AlternatingRowStyle CssClass="browseGridAltRow" />
							<HeaderStyle CssClass="browseGridAltRow" />
							<SelectedRowStyle CssClass="browseGridSelectRow" />
							<Columns>
								<%-- select button is required for each row to enable row selection --%>
								<%-- to allow selection by clicking anywhere on the row, select buttons are hidden and an onClick event is added (by gridRowDataBound) to each row to raise the SelectedIndexChanged event --%>
								<asp:CommandField ShowSelectButton="true" ControlStyle-CssClass="hiddenControl" />
								<%-- permissions flag --%>
								<asp:TemplateField HeaderText="&nbsp">
								<ItemTemplate>
									<div class="browsePermCol truncatedText">
										<%# Eval("EffectivePermission").ToString().ElementAt(0) %>	<%-- bind first letter of each file[i].EffectivePermission --%>
									</div>
								</ItemTemplate>
								<%-- filename --%>
								</asp:TemplateField>
								<asp:TemplateField HeaderText=".. (Parent Folder)">
								<ItemTemplate>
									<table class="browseNameCol truncatedText">
									<tbody>
									<tr>
										<td class="browseFileIcon">
											<img alt='<%# (bool) Eval("IsDir") ? "[dir]" : "[file]" %>' src='<%# (bool) Eval("IsDir") ? "../imgs/folder.png" : "../imgs/file.png" %>' />
										</td>
										<td>
											<%# Eval("FileName") %>		<%-- bind each file[i].FileName --%>
										</td>
									</tr>
									</tbody>
									</table>
								</ItemTemplate>
								</asp:TemplateField>
								<%-- modified datetime and modifier username --%>
								<asp:TemplateField HeaderText="&nbsp">
								<ItemTemplate>
									<div class="browseModifiedCol truncatedText">
										<%# Eval("DateModified").ToString() + " by " + Eval("ModifierName") %>	<%-- bind each file[i].DateModified and file[i].ModifierName --%>
									</div>
								</ItemTemplate>
								</asp:TemplateField>
								<%-- created datetime and creator username --%>
								<asp:TemplateField HeaderText="&nbsp">
								<ItemTemplate>
									<div class="browseCreatedCol truncatedText">
										<%# Eval("DateCreated").ToString() + " by " + Eval("CreatorName") %>	<%-- bind each file[i].DateCreated and file[i].CreatorName --%>
									</div>
								</ItemTemplate>
								</asp:TemplateField>
							</Columns>
						</asp:GridView>
						</div>
					</td>
				</tr>
				</tbody>
				</table>
				</td>
			</tr>
		</tbody>
	</table>
	<br />
	<asp:Label ID="SelectedDirPathLabel" runat="server">/</asp:Label>
	<br />
	<!-- Upload File Form -->
	<table ID="UploadForm" runat="server" class="browseUpload" visible="false">
		<tr>
			<td>
				File:
			</td>
			<td>
				<asp:FileUpload ID="FileUploadControl" runat="server" />
			</td>
		</tr>
		<tr><td /></tr>
		<tr>
			<td>
				<asp:Label runat="server" Text="Upload As: "></asp:Label>
			</td>
			<td>
				<asp:TextBox ID="UploadFileNameTextBox" runat="server" MaxLength="40" Columns="40" Enabled="false"></asp:TextBox>
				<asp:RequiredFieldValidator ID="UploadFileNameRequiredValidator" runat="server" ControlToValidate="UploadFileNameTextBox" ValidationGroup="uploadValidation"
							ErrorMessage="<span style='color:#FF0000'>*</span>" Enabled="false">
				</asp:RequiredFieldValidator>
				<asp:CheckBox ID="UploadFileNewNameCheckBox" runat="server" Text="" OnCheckedChanged="OnCheckedNewFilename" AutoPostBack="true" />
			</td>
		</tr>
		<tr>
			<td />
			<td>
				<asp:RegularExpressionValidator runat="server" ControlToValidate="UploadFileNameTextBox" ValidationGroup="uploadValidation"
							ErrorMessage="<span style='color:#FF0000'>The characters \ / : * ? ' &quot &lt &gt | are not allowed.</span>"
							ValidationExpression="^[a-zA-Z0-9_\-\+\=\[\]\{\} \!\@\#\$\%\^\&\(\)\~\`\,\.\;]*$">
				</asp:RegularExpressionValidator>
			</td>
		</tr>
		<tr>
			<td>
				<asp:Label runat="server" Text="Description: "></asp:Label>
			</td>
			<td>
				<asp:TextBox ID="UploadFileDescriptionTextBox" runat="server" Height="100px" Width="650px" TextMode="MultiLine" MaxLength="65536"></asp:TextBox>
			</td>
		</tr>
		<tr>
			<td />
			<td>
				<asp:Button runat="server" CssClass="masterRegisterButton" text="Upload" onclick="SubmitUploadButton_Click" ValidationGroup="uploadValidation" />
				<asp:Button runat="server" CssClass="masterTabButton" text="Cancel" onclick="CancelUploadButton_Click" />
				<br /><br />
				<asp:Label runat="server" id="UploadFileStatusLabel" Visible="false" text="Upload status: " />
			</td>
		</tr>
	</table>
	<!-- New Folder Name Form -->
	<table ID="NewFolderForm" runat="server" visible="false">
		<tr>
			<td>
				<asp:Label runat="server" Text="New Folder Name:"></asp:Label>
			</td>
			<td>
				<asp:TextBox ID="NewFolderNameTextbox" runat="server" MaxLength="40" Columns="40"></asp:TextBox>
				<asp:RequiredFieldValidator runat="server" ControlToValidate="NewFolderNameTextbox" ValidationGroup="newFolderValidation"
							ErrorMessage="<span style='color:#FF0000'>*</span>">
				</asp:RequiredFieldValidator>
			</td>
		</tr>
		<tr>
			<td />
			<td>
				<asp:RegularExpressionValidator runat="server" ControlToValidate="NewFolderNameTextbox" ValidationGroup="newFolderValidation"
							ErrorMessage="<span style='color:#FF0000'>The characters \ / : * ? ' &quot &lt &gt | are not allowed.</span>"
							ValidationExpression="^[a-zA-Z0-9_\-\+\=\[\]\{\} \!\@\#\$\%\^\&\(\)\~\`\,\.\;]*$">
				</asp:RegularExpressionValidator>
			</td>
		</tr>
		<tr>
			<td>
				<asp:Label runat="server" Text="Description: "></asp:Label>
			</td>
			<td>
				<asp:TextBox ID="NewFolderDescriptionTextBox" runat="server" Height="100px" Width="650px" TextMode="MultiLine" MaxLength="65536"></asp:TextBox>
			</td>
		</tr>
		<tr>
			<td />
			<td>
				<asp:Button runat="server" CssClass="masterRegisterButton" text="Create" onclick="SubmitNewFolderButton_Click" ValidationGroup="newFolderValidation" />
				<asp:Button runat="server" CssClass="masterTabButton" text="Cancel" onclick="CancelNewFolderButton_Click" />
				<br /><br />
				<asp:Label runat="server" ID="NewFolderStatusLabel" Visible="false" text="New Folder status: " />
			</td>
		</tr>
	</table>
	<!-- Delete Confirmation -->
	<table ID="DeleteConfirmation" runat="server" visible="false">
		<tr>
			<td>
				<asp:Label runat="server" Text=":">Confirm</asp:Label>
			</td>
			<td>
				<asp:Label ID="DeleteComfirmationLabel" runat="server" Text=""></asp:Label>
			</td>
		</tr>
		<tr>
			<td />
			<td>
				<asp:Button runat="server" CssClass="masterRegisterButton" text="Delete" onclick="ConfirmDeleteButton_Click" />
				<asp:Button runat="server" CssClass="masterTabButton" text="Cancel" onclick="CancelDeleteButton_Click" />
				<br /><br />
				<asp:Label ID="DeleteStatusLabel" runat="server" Visible="false" text="Delete status: " />
			</td>
		</tr>
	</table>
	<!-- Request Permissions Form -->
	<table ID="PermissionsRequestForm" runat="server" visible="false">
		<tr>
			<td>
				<asp:Label runat="server" Text=":">Desired Permissions</asp:Label>
			</td>
			<td>
				<asp:RadioButton ID="ReadPermissionButton" runat="server" GroupName="permissionRequestButtons" Text="Read" />
				<asp:RadioButton ID="WritePermissionButton" runat="server" GroupName="permissionRequestButtons" Text="Write" />
				<asp:RadioButton ID="AdminPermissionButton" runat="server" GroupName="permissionRequestButtons" Text="Admin" />
			</td>
		</tr>
		<tr>
			<td>
				<asp:Label runat="server" Text="Note: "></asp:Label>
			</td>
			<td>
				<asp:TextBox ID="PermissionRequestNote" runat="server" Height="100px" Width="650px" TextMode="MultiLine" MaxLength="65536"></asp:TextBox>
			</td>
		</tr>
		<tr>
			<td />
			<td>
				<asp:Button ID="SubmitFilePermissionsRequestButton" runat="server" CssClass="masterRegisterButton" text="Request File Permissions" onclick="SubmitPermissionsRequestButton_Click" />
				<asp:Button ID="SubmitDirPermissionsRequestButton" runat="server" CssClass="masterRegisterButton" text="Request Folder Permissions" onclick="SubmitPermissionsRequestButton_Click" />
				<asp:Button ID="CancelPermissionsRequestButton" runat="server" CssClass="masterTabButton" text="Cancel" onclick="CancelPermissionsRequestButton_Click" />
				<br /><br />
				<asp:Label ID="PermissionsRequestStatusLabel" runat="server" Visible="false" text="Request status: " />
			</td>
		</tr>
	</table>
	<br />
	<!-- meta data display -->
	<!-- TODO: make fields updateable -->
	<div class="browseMetaDataDiv">
		
	</div>
</asp:Content>